$(function () {


    /**
     *审核的事件
     */
    $(".merchantsupst").click(function () {

        var upid = parseInt($(this).data("upid"));
        var sta = 2;
        //弹窗提示
        swal({
                title: "确定要审核通过吗？",
                animation: "slide-from-top",
                showCancelButton: true,
                closeOnConfirm: false,
                cancelButtonText: "取消",
                confirmButtonText: "确定"
            },
            function (inputValue) {
                if (inputValue === false) {
                    return false;
                } else {
                    $.ajax({
                        url: "merchantsupst",
                        type: "GET",
                        data: {"upid": upid, "sta": sta},
                        datatype: "JSON",
                        success: function (data) {
                            if (data) {
                                swal({
                                    title: "审核完成,<span style='color:red'>已通过</span>该商户",
                                    html: true,
                                    type: "success",
                                    showCancelButton: false,
                                    showConfirmButton: true,
                                    confirmButtonText: "确定",
                                }, function () {
                                    location.href = "domerchants";
                                });
                            } else {

                            }
                        },
                        error: function (data) {
                            swal({
                                title: '审核失败！',
                                type: 'error',
                                confirmButtonText: '确定',
                                closeOnConfirm: false
                            });
                        }
                    });
                }
            });

    });

    /**
     * 删除的事件
     */
    $(".merchantsdel").click(function () {

        var delid = parseInt($(this).data("delid"));
        //弹窗提示
        swal({
                title: "确定要删除吗？",
                animation: "slide-from-top",
                showCancelButton: true,
                closeOnConfirm: false,
                cancelButtonText: "取消",
                confirmButtonText: "确定"
            },
            function (inputValue) {
                if (inputValue === false) {
                    return false;
                } else {
                    $.ajax({
                        url: "domerchantsdel",
                        type: "GET",
                        data: {"delid": delid},
                        datatype: "JSON",
                        success: function (data) {
                            if (data) {
                                swal({
                                    title: "删除完成,<span style='color:red'>已删除</span>该商户",
                                    html: true,
                                    type: "success",
                                    showCancelButton: false,
                                    showConfirmButton: true,
                                    confirmButtonText: "确定",
                                }, function () {
                                    location.href = "domerchants";
                                });
                            } else {

                            }
                        },
                        error: function (data) {
                            swal({
                                title: '删除失败！',
                                type: 'error',
                                confirmButtonText: '确定',
                                closeOnConfirm: false
                            });
                        }
                    });
                }
            });

    });

});

